<template>
  <div class="MessageList">
    <h3>留言板</h3>
    <!-- // 留言框 -->
    <div class="messageinfo">
      <el-row>
        <el-col :span="2">
          <div class="grid_content">
            <el-avatar :size="60"> {{ userinfo.nickname }}</el-avatar>
          </div>
        </el-col>
        <el-col :span="15">
          <div class="bg_purple">
            <el-input v-model="input" placeholder="请输入内容"></el-input>
          </div>
        </el-col>
        <el-col :span="6">
          <div class="bg_purple grid_el-co">
            <el-button type="success" icon="el-icon-message" @click.native="submitsend"></el-button>
          </div>
        </el-col>
      </el-row>
    </div>
    <el-collapse v-model="activeName" accordion class="el-collapse">
      <el-collapse-item class="el-collapse-item" v-for="(i, l) in commentlist" :key="l" :name="l">
        <template slot="title">
          <el-avatar size="medium">{{ i.comment.user.nickname }} </el-avatar>
          <h5>{{ i.comment.content }}</h5></template
        >

        <!-- // 回复留言 -->
        <el-row class="el-row-huifu">
          <el-col :span="2">
            <div class="grid_content_text">回复他</div>
          </el-col>
          <el-col :span="15">
            <div class="bg_purple">
              <el-input v-model="inputtext" placeholder="请输入内容"></el-input>
            </div>
          </el-col>
          <el-col :span="6">
            <div class="bg_purple grid_el-co">
              <el-button
                type="text"
                :disabled="i.comment.user.nickname == userinfo.nickname"
                @click.native="submit(i.comment.personal_car_id, i.comment.id)"
                >回复</el-button
              >
            </div>
          </el-col>
        </el-row>
        <!-- 回复列表 -->
        <el-row class="elrow" v-for="(item, len) in i.replyList" :key="len">
          <div v-if="i.replyList">
            <el-col :span="3">
              <div class="bg_purple_reply el-col-left">{{ item.user.nickname }}:</div>
            </el-col>
            <el-col :span="13">
              <div class="bg_purple_reply">
                <span> {{ item.content }}</span>
              </div>
            </el-col>
          </div>
        </el-row>
      </el-collapse-item>
    </el-collapse>
  </div>
</template>

<script>
import { sendComment, queryComment, replyComment } from '@/api/user'
export default {
  name: 'MessageList',
  data() {
    return {
      activeName: '1',
      inputtext: '',
      input: '',
      commentlist: [] // 留言列表
    }
  },
  created() {
    this.querySend()
  },
  methods: {
    async submit(a, b) {
      await replyComment({ personal_car_id: a, comment_id: b, content: this.inputtext })
      this.querySend()
    },
    async querySend() {
      const query = this.$route.query
      const res = await queryComment({ id: query.id })
      this.commentlist = res.data.data
    },
    async submitsend() {
      const query = this.$route.query
      await sendComment({ personal_car_id: query.id, content: this.input })
      this.querySend()
    }
  },
  computed: {
    userinfo: function () {
      return this.$store.state.user.profile
    }
  }
}
</script>
<style lang="less" scoped>
.el-collapse {
  padding-left: 50px;
  .el-collapse-item {
    padding-right: 80px;
    h5 {
      padding-left: 20px;
    }
  }
}
.MessageList {
  margin-top: 20px;
  .messageinfo {
    padding-bottom: 20px;
    border-bottom: 1px solid #eee;
  }
  .el-collapse-item {
    list-style: none;
    .el-row-huifu {
      border-top: 1px solid #eee;
      margin-bottom: 10px;
    }
    .grid_content_text {
      line-height: 40px;
      padding-top: 10px;
      padding-left: 30px;
    }
    .elrowlist {
      border-bottom: 1px solid #eee;
    }
    .el-col-left {
      padding-left: 80px;
      text-align: right;
      color: #409eff;
    }
  }
  .bg_purple {
    h5 {
      margin-top: 0;
      margin-bottom: 10px;
    }
    padding-top: 10px;
  }
  .grid_el-co {
    padding-left: 10px;
  }
}
</style>
